<template>
  <a-row type="flex" style="flex-flow: inherit;">
    <a-col :flex="toggle?'260px':'30px'" style="margin-right: 12px;background-color: #fff;">
      <depart-tree :rootOpened="true" :multi="false" @ok="getTreeData" @toggleBool="toggleBool" />
    </a-col>
    <a-col flex="auto">
      <a-card :bordered="false" style="margin-bottom: 10px">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form-model layout="inline" ref="ruleForm" :model="queryParam">
            <z-form-item :datas="fieldArr" :form="queryParam" :gutter="8" :toggle="toggleSearchStatus">
              <a-col :span="4" slot="submit-action">
                <a-space :size="6">
                  <a-button type="primary" @click="onQuery" icon="search">查询</a-button>
                  <a-button @click="onResetForm" icon="reload">重置</a-button>
                </a-space>
              </a-col>
            </z-form-item>
          </a-form-model>
        </div>
      </a-card>
      <a-card :bordered="false">
        <!-- 表格展示 -->
        <div class="table-page-content">
          <z-table
            ref="table"
            rowKey="id"
            :showAlert="false"
            :showSelection="false"
            :loading="loading"
            :columns="columns"
            :dataSource="pageData"
            @selectedRow="onSelectedRow"
            @change="onTableChange"
          >
            <template slot="currentStage" slot-scope="text, record">
              <div>
                {{ currentStageText(text,'T') }}
              </div>
              <div>
                <a-progress :title="record.num === '0' ? '' : `超过规定完成时间${record.num}天` " :status="record.num === '0' ? 'active' : 'exception' " :percent="currentStageText(text,'N')" size="small" />
              </div>
            </template>
          </z-table>
        </div>
        <!--弹窗区域-->
        <suoerviseJmodal ref="suoerviseJmodal" @ok="modalFormOk" />
      </a-card>
    </a-col>
  </a-row>
</template>

<script>
import departTree from '../../../modules/departTree'
import {listFor,listForm} from "@views/sjsk/modules/list";
import {ManageList, pageNew, PointEnter} from "@api/sjsk/receiveCase";
import suoerviseJmodal from "@views/sjsk/management/join/supervise/suoerviseJmodal";

export default {
  components: { departTree, suoerviseJmodal },
  mixins:[listFor,listForm],
  data() {
    return {
      statusCU:'active',
      lookTer:true,
      toggle: true,
      selectKeys: [],
      queryParam: {},
      /* 查询折叠 */
      toggleSearchStatus:true,
      fieldArr: [
        {label: '姓名', prop: 'name', tagType: 'input', span: 5},
        {label: '身份证号', prop: 'identification', tagType: 'input', span: 5},
        {label: '当前阶段', prop: 'status', tagType: 'dict-select', dictCode:'Dqjieduan', span: 5},
        {label: '监所类型', prop: 'dataType', tagType: 'dict-select', dictCode:'prisons_type', span: 5}
      ],
      pageData:[
        // {
        //   caseNo:'25890476',
        //   realName:'林远东',
        //   identityCard:'542505425054250',
        //   receiveExecPlace:'塔寨村',
        //   enterEndTime:'2023/01/01',
        //   currentStage:'0',
        //   num:'0',
        //   actualDepartureTime:'2023/01/01',
        //   dataSource:'枪毙死刑！！！！！'
        // },
        // {
        //   caseNo:'25890476',
        //   realName:'林远东',
        //   identityCard:'542505425054250',
        //   receiveExecPlace:'塔寨村',
        //   enterEndTime:'2023/01/01',
        //   currentStage:'1',
        //   num:'0',
        //   actualDepartureTime:'2023/01/01',
        //   dataSource:'枪毙死刑！！！！！'
        // },
        // {
        //   caseNo:'25890476',
        //   realName:'林远东',
        //   identityCard:'542505425054250',
        //   receiveExecPlace:'塔寨村',
        //   enterEndTime:'2023/01/01',
        //   currentStage:'2',
        //   num:'0',
        //   actualDepartureTime:'2023/01/01',
        //   dataSource:'枪毙死刑！！！！！'
        // },
        // {
        //   caseNo:'25890476',
        //   realName:'林远东',
        //   identityCard:'542505425054250',
        //   receiveExecPlace:'塔寨村',
        //   enterEndTime:'2023/01/01',
        //   currentStage:'3',
        //   num:'0',
        //   actualDepartureTime:'2023/01/01',
        //   dataSource:'枪毙死刑！！！！！'
        // },
        // {
        //   caseNo:'25890476',
        //   realName:'林远东',
        //   identityCard:'542505425054250',
        //   receiveExecPlace:'塔寨村',
        //   enterEndTime:'2023/01/01',
        //   currentStage:'4',
        //   num:'0',
        //   actualDepartureTime:'2023/01/01',
        //   dataSource:'枪毙死刑！！！！！'
        // },
        // {
        //   caseNo:'25890476',
        //   realName:'林远东',
        //   identityCard:'542505425054250',
        //   receiveExecPlace:'塔寨村',
        //   enterEndTime:'2023/01/01',
        //   currentStage:'5',
        //   num:'0',
        //   actualDepartureTime:'2023/01/01',
        //   dataSource:'枪毙死刑！！！！！'
        // },
        // {
        //   caseNo:'25890476',
        //   realName:'林远东',
        //   identityCard:'542505425054250',
        //   receiveExecPlace:'塔寨村',
        //   enterEndTime:'2023/01/01',
        //   currentStage:'3',
        //   num:'1',
        //   actualDepartureTime:'2023/01/01',
        //   dataSource:'枪毙死刑！！！！！'
        // }
      ],
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          width: 60,
          align: 'center',
          customRender: (text, record, index) =>
            `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
        },
        {
          title: '个案编号',
          dataIndex: 'caseNo',
          width: 40,
          align: 'left',
          customRender: text => {
            return <j-ellipsis value={text} length={3} />
          }
        },
        {
          title: '姓名',
          width: 40,
          align: 'left',
          dataIndex: 'realName',
          customRender: text => {
            return <j-ellipsis value={text} length={20} />
          }
        },
        {
          title: '身份证号',
          dataIndex: 'identityCard',
          width: 110,
          align: 'left',
          customRender: text => {
            return <j-ellipsis value={text} length={20} />
          }
        },
        {
          title: '接收执行地',
          dataIndex: 'receiveExecPlace',
          width: 60,
          align: 'center',
          customRender: text => {
            if(text){
              return <j-ellipsis value={text} length={14} />
            } else {
              return '--'
            }

          }
        },
        {
          title: '截至日期',
          dataIndex: 'enterEndTime',
          width: 100,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '当前阶段',
          dataIndex: 'currentStage',
          width: 80,
          align: 'center',
          scopedSlots: { customRender: 'currentStage' }
        },
        {
          title: '出所日期',
          dataIndex: 'actualDepartureTime',
          width: 80,
          align: 'center',
          customRender: text => {
            if(text){
              return <j-ellipsis value={text} length={14} />
            } else {
              return '--'
            }
          }
        },
        {
          title: '监所类型',
          dataIndex: 'dataSource',
          width: 80,
          align: 'center',
          customRender: text => {
            if(text === 2){
              return '公安监所'
            } else {
              return '司法监所'
            }
          }
        },
        {
          title: '操作',
          width: 120,
          align: 'center',
          dataIndex: 'action',
          customRender: (text, record, index) => {
            return (
              <a-space size={6}>
                <a type="link" style={'padding:0'} onClick={event => this.handleModal(record)}>转介</a>
                <a type="link" style={'padding:0'} onClick={event => this.suoerviseJmodal(record)}>出所衔接</a>
              </a-space>
            )
          }
        }
      ],
    }
  },
  created() {},
  async mounted() {
    // this.onQuery()
  },
  methods: {
    onResetForm() {
      // this.queryParam = {}
      delete this.queryParam.name
      delete this.queryParam.identification
      delete this.queryParam.status
      delete this.queryParam.dataType
      this.pageFilter.pageNo = 1
      this.pageFilter.pageSize = 10
      this.refreshTable()
      // this.$refs.ruleForm.ruleForm()
    },
    renovate(){
      this.refreshTable()
    },
    reload() {
      this.reloading = true
      this.$nextTick(() => (this.reloading = false))
    },
    onQuery() {
      console.log(this.queryParam)
      this.pageFilter.pageNo = 1
      this.refreshTable()
    },

    lookRouter(val){
      this.lookTer = val !== 1;
    },
    refreshTable() {
      let queryParam = Object.assign({}, this.queryParam, this.pageFilter)
      this.loading = true
      ManageList(queryParam)
        .then(res => {
          console.log(res)
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
            this.$refs.table.onClearRowKeys()
          } else {
            this.$message.error(res.message);
            this.loading = false
          }
        })
        .catch(e => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    currentStageText(text,bt){
      let nav = 0
      let textStr = ''
      if(text === '0'){
        nav = 0
        textStr = '通知送戒单位'
      }
      if(text === '1'){
        nav = 20
        textStr = '送戒单位上传材料'
      }
      if(text === '2'){
        nav = 40
        textStr = '人员出所通知'
      }
      if(text === '3'){
        nav = 60
        textStr = '通知专干/社工人员'
      }
      if(text === '4'){
        nav = 80
        textStr = '人员接收'
      }
      if(text === '5'){
        nav = 100
        textStr = '完成出所'
      }
      if(bt === 'T'){
        return textStr
      }
      if (bt === 'N'){
        return nav
      }
    },
    modalFormOk() {},
    // 弹窗操作
    handleModal(record) {
      this.$refs.suoerviseJmodal.show(record.id)
    },
    suoerviseJmodal(record){
      this.$router.push({
        path:'/supervise/cohesion',
        query:record
      })
    },
    getTreeData(datas, id) {
      this.queryParam.departmentId = id
      this.onQuery()
      console.log(datas)
      console.log(id)
    },
    toggleBool(bool) {
      console.log(bool)
      this.toggle = bool
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
</style>
